package com.cnt.util;

import com.cnt.dao.DonationRecordsDao;
import com.cnt.dao.MoneyLogDao;
import com.cnt.dao.UserLogDao;
import com.cnt.entity.DonationRecords;
import com.cnt.entity.MoneyLog;
import com.cnt.entity.UserLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class LogUtil {

    @Autowired
    private UserLogDao userLogDao;
    @Autowired
    private DonationRecordsDao donationRecordsDao;
    @Autowired
    private MoneyLogDao moneyLogDao;

    public void recordMoneyLog(int flag,int userId, String transferId, String msg){
        MoneyLog moneyLog = new MoneyLog();
        moneyLog.setFlag(flag);
        moneyLog.setUserId(userId);
        moneyLog.setTransferId(transferId);
        moneyLog.setTime(new Date());
        moneyLog.setMessage(msg);
        moneyLogDao.insert(moneyLog);
    }

    public void recordDonation( int donationId, int userId, double donationAmount){
        DonationRecords donationRecords = new DonationRecords();
        donationRecords.setDonationAmount(donationAmount);
        donationRecords.setDonationTime(new Date());
        donationRecords.setDonationId(donationId);
        donationRecords.setUserId(userId);
        donationRecordsDao.insert(donationRecords);
    }


    public void recordLog(Integer userId, String msg) {
        UserLog userLog = new UserLog();
        userLog.setUserId(userId);
        userLog.setLogTime(new Date());
        userLog.setLogMessage(msg);
        System.out.println(userLog);
        userLogDao.insert(userLog);
    }
}
